package com.atguigu.gulimall.product.controller;

import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gulimall.product.service.BloomService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author nicc
 * @version 1.0
 * @className BloomController
 * @date 2022-10-10 19:20
 */
@Api(tags = "布隆过滤器")
@RequestMapping("/admin/product")
@RestController
@Slf4j
public class BloomController {

    @Autowired
    BloomService bloomService;

    @Autowired
    RedissonClient redisson;

    /**
     * 重置布隆
     * @return
     */
    @GetMapping("/bloom/reset")
    public Result resetBloom(){

        bloomService.reset(RedisConst.BLOOM_SKUID);

        RBloomFilter<Object> filter = redisson.getBloomFilter(RedisConst.BLOOM_SKUID);
        return Result.ok(filter.contains(99L));
    }

}